package com.tuo51.partner.controller;


import com.alibaba.fastjson.JSON;
import com.aliyun.oss.HttpMethod;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import com.aliyun.oss.model.OSSObject;
import com.google.common.collect.ImmutableMap;
import com.tuo51.foudation.model.StatusResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static com.tuo51.foudation.constant.RequestConstant.*;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * 测评小程序使用的接口
 */

@RestController
@RequestMapping("/partner")
@Api(value = "/partner", tags = "伙伴接口 - ")
public class PartnerController {

    @ApiOperation("测试")
    @RequestMapping(value = "/test", method = POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "partner", value = "伙伴 id，测评师为 express", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "uuid", value = "随机生成的 uuid，用以防重复提交放反推", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "compver", value = "组件版本，当前为 1", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "auth", value = "签名，签名算法见范例", required = true, dataType = "string")
    })
    public StatusResponse handshake(@RequestHeader(PARTNERID_KEY) String partner,
                                      @RequestHeader(AUTH_KEY) String auth,
                                      @RequestHeader(REQ_UUID_KEY) String uuid,
                                      @RequestHeader(COMP_VERSION_KEY) String compver){

        return StatusResponse.success("hello");

    }

    /**
     * 阿里云API的内或外网域名  //替换成自己的
     */
    private static final String ENDPOINT =  "http://oss-cn-shenzhen.aliyuncs.com";;
    /**
     * 阿里云API的密钥Access Key ID   //替换成自己的
     */
    private static final String ACCESS_KEY_ID ="LTAIUMdRxLE76RPq";
    /**
     * 阿里云API的密钥Access Key Secret   //替换成自己的
     */
    private static final String ACCESS_KEY_SECRET ="6LI0JGzMNY21ehtaupE0IFMw5VGMov";
    /**
     * 阿里云API的bucket名称    //替换成自己的
     */
    private static final String BACKET_NAME = "com-blearning-img";

    @ApiOperation("OSS测试")
    @RequestMapping(value = "/oss_test", method = GET)
    public static void test(HttpServletResponse response) {
        List<Map<String, String>> fileNames = new ArrayList<>();


        String jsonstr = "[\n" +
                "[\"张先生\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210228165508167758519_739A1277-C94C-497F-91D8-B62079BC6A12.jpeg\",\"430105198106181510\"],\n" +
                "[\"许杰\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210304081634304866102_许杰1_20210304161018.jpg\",\"430124198701088678\"],\n" +
                "[\"曹伟\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210319073244047672910_99386b034594b90df9ccb29bb33a2c9_看图王.jpg\",\"340123198803087694\"],\n" +
                "[\"张永强\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210322001438074837177_报名照片1.jpg\",\"130425198302163513\"],\n" +
                "[\"解正富\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210322100841601027699_75022739415282887.jpg\",\"340122198009106230\"],\n" +
                "[\"吴宝庆\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210323043934302427399_微信图片_20210323123910.jpg\",\"230225198504092015\"],\n" +
                "[\"万强\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210326110110743951362_二建考试照片.jpg\",\"360102199306076317\"],\n" +
                "[\"李方良\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210329070731435829627_1c6a25cac7de8a1c9062698bfcf4df6.png\",\"430523198808304137\"],\n" +
                "[\"蔡志亮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210329071929216458180_psb.jpg\",\"36012219881225421X\"],\n" +
                "[\"左晋\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210329073644165053599_88fb210659c426d44743c02a9ab1055.jpg\",\"362430199702177519\"],\n" +
                "[\"刘万代\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210329083319606976316_6、刘万代证件照(1).jpg\",\"37078519830615091X\"],\n" +
                "[\"陈德胜\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210329140440325425632_IMG_20180225_141118.jpg\",\"430422198606271216\"],\n" +
                "[\"陈代金\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330045425365731122_IMG_20210330_124840.jpg\",\"430726198112114810\"],\n" +
                "[\"周云\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330052020389896301_16170815621203596543961796771228.jpg\",\"430726198408055434\"],\n" +
                "[\"陈代纯\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330052056138204041_IMG20190608115145.jpg\",\"430726198104034810\"],\n" +
                "[\"孙海涛\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330100842750792666_IMG_20210330_180431.jpg\",\"341225198505262334\"],\n" +
                "[\"徐世强\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330113506258402106_psc[3].jpg\",\"360104198902061515\"],\n" +
                "[\"胡杰\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330124506052016520_1617108197.jpg\",\"430422198106111574\"],\n" +
                "[\"黄国云\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330130729258511048_微信图片_20210330210713.jpg\",\"430422198505101218\"],\n" +
                "[\"郭明\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210330134222697318661_IMG_20210330_104039.jpg\",\"432827197508147618\"],\n" +
                "[\"田运佳\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210331015046681991998_20210331_094635.jpg\",\"430321198212131577\"],\n" +
                "[\"覃志渊\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210331053339621319883_JPEG_20210331_131653_1311053954128075687.jpg\",\"432427197104185413\"],\n" +
                "[\"覃道国\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210331073243690581396_20210331122338546.jpg\",\"430726198008204816\"],\n" +
                "[\"王振\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210331131251307106372_2021-03-31_21.11.52.jpg\",\"430726198804094857\"],\n" +
                "[\"张雪虎\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210331224916066416161_IMG_20210331_211847.jpg\",\"341225198504132351\"],\n" +
                "[\"陈代伟\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210401034320709383212_1617248551707.jpg\",\"432427197908134814\"],\n" +
                "[\"覃业举\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210402140714291128696_mmexport1616767617007.jpg\",\"430726198201304819\"],\n" +
                "[\"张亮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210409114535628434154_微信图片_20210409194713.jpg\",\"412922198410162013\"],\n" +
                "[\"万强\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210410105105737834452_二建考试照片.jpg\",\"360102199306076317\"],\n" +
                "[\"肖在\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210413061347987500985_5.jpg\",\"430124197811099373\"],\n" +
                "[\"赵利\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210414074457033747122_90e8c0868477f6ba648956fe150b1d11\",\"420322198609194212\"],\n" +
                "[\"谭觉\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210414204142196993678_hd_1618432541359.png\",\"430624198612124814\"],\n" +
                "[\"刘万代\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210414232315216569293_6、刘万代证件照(1).jpg\",\"37078519830615091X\"],\n" +
                "[\"张永强\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210414234435231611495_申硕_20190322105007.jpg\",\"130425198302163513\"],\n" +
                "[\"张龙\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415002557991775470_zhaopian.PNG\",\"430721197312280016\"],\n" +
                "[\"曹伟\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415003441931596990_考试照片.jpg\",\"340123198803087694\"],\n" +
                "[\"龚旭民\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415010439846060936_IMG_20210415_090401.jpg\",\"430725198502282178\"],\n" +
                "[\"喻正龙\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415014650329126186_20201118152547840.jpg\",\"430124198011074973\"],\n" +
                "[\"曹怀\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415015354967563089_IMG_20210415_095310.jpg\",\"431226198605232413\"],\n" +
                "[\"郭政\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415020341484437432_IMG_20210317_104804.jpg\",\"430121198711134931\"],\n" +
                "[\"刘依\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415021910199292193_mmexport1618453299777.jpg\",\"430121199103131539\"],\n" +
                "[\"赵尤雁\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415021758791242632_赵尤雁 白底电子照.jpg\",\"522625198602092176\"],\n" +
                "[\"蔡志亮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415022401967796651_报名照片.jpg\",\"36012219881225421X\"],\n" +
                "[\"刘攀\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415023727435029117_mmexport1618454216496.jpg\",\"430725198710172176\"],\n" +
                "[\"徐世强\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415031322269937028_658175b5e5ff6ccd71d786fb4e1819fc_mnull&bo=JwGdAQAAAAAFB54!&rf=photolist&t=5.jpg\",\"360104198902061515\"],\n" +
                "[\"付媛媛\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415031716078673417_图片1.png\",\"430802199110014807\"],\n" +
                "[\"刘政\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415031532988680986_IMG_20210415_100052.png\",\"430703198010143536\"],\n" +
                "[\"崔天龙\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415032330508726793_zhaopian.png\",\"430802197808233412\"],\n" +
                "[\"赵六顺\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415034317337391510_图片1.png\",\"430802197701121912\"],\n" +
                "[\"左晋\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415051033740109975_88fb210659c426d44743c02a9ab1055.jpg\",\"362430199702177519\"],\n" +
                "[\"吴鹏程\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415051656792167137_image.jpg\",\"430821198601135114\"],\n" +
                "[\"刘坤\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415061847256061616_照片-2.jpg\",\"610121198511023296\"],\n" +
                "[\"李稳\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415062919728879932_mmexport1618467998520.jpg\",\"430321198703057033\"],\n" +
                "[\"刘亮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415070328088347849_mmexport1618469873342.jpg\",\"430981198609176318\"],\n" +
                "[\"陈杰\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415072818884890951_陈杰.jpg\",\"430124198706292010\"],\n" +
                "[\"李方良\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415075824747248616_1c6a25cac7de8a1c9062698bfcf4df6.png\",\"430523198808304137\"],\n" +
                "[\"肖寒\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415083913207537241_1618476158(1).png\",\"430681198710069334\"],\n" +
                "[\"王集伟\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210415095434575187063_1618480449(1).png\",\"43048119840208569X\"],\n" +
                "[\"曹刚刚\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416003819861655215_mmexport1618533489583.jpg\",\"429001198412070830\"],\n" +
                "[\"何岳龙\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416011042375808891_照片.jpg\",\"430321198004075515\"],\n" +
                "[\"唐奥\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416013823522310632_微信图片_20210416094028.png\",\"430922199305101733\"],\n" +
                "[\"邓光龙\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416022337833378082_微信图片_20210416102313.jpg\",\"422425197801135230\"],\n" +
                "[\"彭铁均\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416025832202580446_1618541840.png\",\"430124197612198213\"],\n" +
                "[\"姚泽楷\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416034906957958072_C4A57A66-9210-4EA8-93E9-E96708961E8B.png\",\"440582199409120054\"],\n" +
                "[\"钟嘉妮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416035416789325982_C75B2B62-C968-47E3-9780-DB716C962EE9.png\",\"440514199611244927\"],\n" +
                "[\"李六一\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416053121065445929_b893f6769db63fa1e16289f7fbab66c.jpg\",\"610526198002233416\"],\n" +
                "[\"高建苹\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416060002454018301_微信图片_20210416135820.jpg\",\"422802198712131731\"],\n" +
                "[\"李余\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416060000443178228_123.png\",\"430681198511169316\"],\n" +
                "[\"张强\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416065600549727928_7、一寸证件照-张强.jpg\",\"320311198701085550\"],\n" +
                "[\"陈德胜\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416074832899841119_IMG_20180225_141118.jpg\",\"430422198606271216\"],\n" +
                "[\"肖伟贤\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416082345857373734_肖伟贤.jpg\",\"440784198008144812\"],\n" +
                "[\"管志涛\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416093151944436983_MYXJ_20180808134030_save.jpg\",\"320481199110041811\"],\n" +
                "[\"潘高\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416101621628219166_潘高.jpg\",\"510722198909244510\"],\n" +
                "[\"邹凯\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416101705416190612_IMG_20200819_215954.jpg\",\"430122198712296015\"],\n" +
                "[\"吴勇\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416103146592595813_IMG_20210319_111231.jpg\",\"430122198203301613\"],\n" +
                "[\"罗英晖\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416123936996005046_1C432947-794C-45C9-BDA7-2085640D9030.jpeg\",\"445122199005253797\"],\n" +
                "[\"周云\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416140330703570250_16185817796483483700219104890690.jpg\",\"430726198408055434\"],\n" +
                "[\"陈代金\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210416141201975474186_IMG_20210330_124840.jpg\",\"430726198112114810\"],\n" +
                "[\"魏超\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210417073736566330288_mmexport1618645029636.png\",\"430725198909083058\"],\n" +
                "[\"覃志渊\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210417135730235562903_IMG20210331132232.jpg\",\"432427197104185413\"],\n" +
                "[\"陈凯\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210417164225317911278_IMG_20210317_120054.jpg\",\"430381198901202672\"],\n" +
                "[\"覃明亮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210417171542397734517_Screenshot_20210418_011140_com.android.gallery3d_edit_537127315774289.jpg\",\"430726198509154810\"],\n" +
                "[\"覃道国\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210418044729616849527_1618720826693.jpg\",\"430426198008204816\"],\n" +
                "[\"胡亮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210418072525345150994_hdImg_cc3a178992c4e64529bc491136552f501618730713969.jpg\",\"430681198710039311\"],\n" +
                "[\"莫锦珊\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210418084133371192386_mmexport1618735031855.jpg\",\"440825198710240551\"],\n" +
                "[\"张亮\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210418083718687929960_IMG_4748.JPG\",\"430681198109093712\"],\n" +
                "[\"王建长\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210418090936825909248_证件.png\",\"620522198603133716\"],\n" +
                "[\"张威13469079331\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210418140936995792829_image.jpg\",\"430121198708054914\"],\n" +
                "[\"丁科\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210419025853856446934_mmexport1618801019969.jpg\",\"430703197811253511\"],\n" +
                "[\"胡杰\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210419133321847260561_微信图片_20210419213112333.jpg\",\"430422198106111574\"],\n" +
                "[\"王马可\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210419140008935458065_IMG_20210212_133036.jpg\",\"411381199708153014\"],\n" +
                "[\"张雪虎\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210419141038072185514_微信图片_20210419221030.jpg\",\"341225198504132351\"],\n" +
                "[\"黄国云\",\"http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/PCTS_20210420151310371840814_微信图片_20210420231253.jpg\",\"430422198505101218\"]]\n";

        List jsonObjs = JSON.parseArray(jsonstr);

        for (int i = 0; i < jsonObjs.size(); i++){
            Object r = jsonObjs.get(i);
            List record = (List)r;

            String name = (String) record.get(0);
            String url = (String) record.get(1);
            String idcard = (String) record.get(2);

            String prefix = "http://com-blearning-img.oss-cn-shenzhen.aliyuncs.com/";
            String path = url.startsWith(prefix) ? url.substring(prefix.length()) : url;

            fileNames.add(ImmutableMap.of("path", path, "idcard", i + " " + name + "_" + idcard));

        }

        String zipFileName = "photos";

        batchDownLoadOssFile(fileNames, zipFileName, response);
    }

    public static void batchDownLoadOssFile(List<Map<String, String>> fileNames, String zipFileName, HttpServletResponse response) {

        //fileNames 需要相对路径

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition", "attachment;fileName=" + zipFileName + ".zip");
        BufferedInputStream bis = null;
        try {
            ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
            OSSClient ossClient = new OSSClient(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
            int sortNum = 0;


            for (Map<String, String> fileName : fileNames) {
                Date expiration = new Date(System.currentTimeMillis() + 3600 * 1000);

                String path = fileName.get("path");
                String idcard = fileName.get("idcard");

                GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(BACKET_NAME, path, HttpMethod.GET);
                // 设置过期时间。
                request.setExpiration(expiration);
                // 生成签名URL（HTTP GET请求）。
                URL signedUrl = ossClient.generatePresignedUrl(request);
                // 使用签名URL发送请求。
                OSSObject ossObject = ossClient.getObject(signedUrl, new HashMap<>());

                if (ossObject != null) {
                    InputStream inputStream = ossObject.getObjectContent();
                    byte[] buffs = new byte[1024 * 10];

//                    String zipFile = sortNum + "_" + fileName.substring(fileName.lastIndexOf("/") + 1);
//                    String zipFile = idcard + path.substring(path.lastIndexOf("."));
                    int index = path.lastIndexOf(".");
                    String zipFile = index >= 0 ? idcard + path.substring(index) : idcard ;

                    ZipEntry zipEntry = new ZipEntry(zipFile);
                    zos.putNextEntry(zipEntry);
                    bis = new BufferedInputStream(inputStream, 1024 * 10);

                    int read;
                    while ((read = bis.read(buffs, 0, 1024 * 10)) != -1) {
                        zos.write(buffs, 0, read);
                    }
                    ossObject.close();
                }
                sortNum++;
            }
            zos.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭流
            try {
                if (null != bis) {
                    bis.close();
                }
                response.getOutputStream().flush();
                response.getOutputStream().close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
